/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package window;

import busEvents.ChangeViewEvent;
import com.adamtaft.eb.EventBusService;
import data.AccountData;
import data.Data;
import enums.ViewEnum;

/**
 *
 * @author Arcanis
 */
public class SettingsPanel extends javax.swing.JPanel {

    private Data data = null;

    /**
     * Creates new form Settings
     */
    public SettingsPanel() {
        initComponents();
    }

    public void setAccountData(AccountData data1, AccountData data2) {
        accountDataPanel1.setData(data1);
        accountDataPanel4.setData(data2);
    }

    public void setData(Data data) {
        this.data = data;
    }

    /**
     * This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        accountDataPanel4 = new windowComponents.AccountDataPanel(true);
        accountDataPanel1 = new windowComponents.AccountDataPanel(false);
        jButton1 = new javax.swing.JButton();

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/kuba_icon_ok.png"))); // NOI18N
        jButton1.setToolTipText("Použít");
        jButton1.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(accountDataPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(accountDataPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(accountDataPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(14, 14, 14)
                .addComponent(accountDataPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if (data != null) {
            data.loadAccount();
            data.notifyObservers();
            EventBusService.publish(new ChangeViewEvent(ViewEnum.RECV_EMAILS));
        }
    }//GEN-LAST:event_jButton1ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private windowComponents.AccountDataPanel accountDataPanel1;
    private windowComponents.AccountDataPanel accountDataPanel4;
    private javax.swing.JButton jButton1;
    // End of variables declaration//GEN-END:variables
}
